//
//  HWMineCell.swift
//  HWanGame
//
//  Created by 王昌健 on 2021/12/22.
//  Copyright © 2021 94Wan. All rights reserved.
//

import UIKit

class HWMineCell: UITableViewCell {
    var topView:HWMineTopView!
    
    var bottomView:HWMineBottomView!

    var model:HWMineModel? {
        didSet {
            topView.model = model
            bottomView.model = model
        }
    }
    var showBadge:Bool? {
        didSet {
            topView.showBadge = showBadge
        }
    }
    
    var navClick:((_ model:HWMineNavModel)->())?
    var itemButtonClick:((_ id:String)->())?
    var moreButtonClick:(()->())?
    /// 消息
    var messageButtonClick:(()->())?
    /// 设置
    var settingButtonClick:(()->())?
    /// 签到
    var signButtonClick:(()->())?
    /// 开通Vip
    var openVipButtonClick:(()->())?
    /// 个人信息
    var mineInfoButtonClick:(()->())?
    /// 卡券
    var cardButtonClick:(()->())?
    /// 钱包
    var walletButtonClick:(()->())?
    /// 我的游戏
    var myGameButtonClick:(()->())?
    /// 我的关注
    var myFollowButtonClick:(()->())?
    class func cellWithTableView(tableView:UITableView) -> (HWMineCell) {
        let reUse:String = "HWMineCell"
        
        var cell = tableView.dequeueReusableCell(withIdentifier: reUse)
        
        if cell == nil {
            cell = HWMineCell.init(style: UITableViewCell.CellStyle.default, reuseIdentifier: reUse)
        }
        
        return cell as! HWMineCell
    }
    
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        initUI()
        initFrame()
    }
    
    func initUI() -> Void {
        selectionStyle = UITableViewCell.SelectionStyle.none
        backgroundColor = UIColor.clear
        
        topView = HWMineTopView()
        contentView.addSubview(topView)
        
        bottomView = HWMineBottomView()
        contentView.addSubview(bottomView)
        
        topView.messageButtonClick = {
            self.messageButtonClick?()
        }
        
        topView.settingButtonClick = {
            self.settingButtonClick?()
        }
        
        topView.mineInfoButtonClick = {
            self.mineInfoButtonClick?()
        }
        
        topView.signButtonClick = {
            self.signButtonClick?()
        }
        
        topView.openVipButtonClick = {
            self.openVipButtonClick?()
        }
        
        topView.cardButtonClick = {
            self.cardButtonClick?()
        }
        
        topView.walletButtonClick = {
            self.walletButtonClick?()
        }
        
        topView.myGameButtonClick = {
            self.myGameButtonClick?()
        }
        
        topView.myFollowButtonClick = {
            self.myFollowButtonClick?()
        }
        
        bottomView.navClick = {
            mod in
            self.navClick?(mod)
        }
        
        bottomView.moreButtonClick = {
            self.moreButtonClick?()
        }
        
        bottomView.itemButtonClick = {
            id in
            self.itemButtonClick?(id)
        }
        
    }
    
    func initFrame() -> Void {
        topView.snp.makeConstraints { make in
            make.left.top.right.equalToSuperview()
        }
        
        bottomView.snp.makeConstraints { make in
            make.left.right.bottom.equalTo(0)
            make.top.equalTo(topView.openVipButton.snp.bottom).offset(14*widthScale)
        }
        
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}

